package com.huilian.iotbox.client.service.impl;

import com.huilian.iotbox.client.dao.CustomerServiceInfoDao;
import com.huilian.iotbox.client.service.CustomerServiceInfoService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.CustomerServiceInfoDto;
import com.huilian.iotbox.data.dto.MemberDto;
import com.huilian.iotbox.data.vo.CustomerServiceInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 龙 路 飞
 * @CreateDate: 2021-11-09 16:10
 * @Description:
 */
@Service
public class CustomerServiceInfoServiceImpl implements CustomerServiceInfoService {

    @Autowired
    private CustomerServiceInfoDao customerServiceInfoDao;

    @Override
    public ServerResponse findCustomerServiceInfoByApplet(CustomerServiceInfoDto customerServiceInfoDto, MemberDto memberFromReq) {

        if (StringUtils.isEmpty(customerServiceInfoDto.getMerchantStoreId())) {
            return ServerResponse.createByErrorMessage("场地ID不能为空");
        }

        if (StringUtils.isEmpty(customerServiceInfoDto.getDeviceNo())) {
            return ServerResponse.createByErrorMessage("设备号不能为空");
        }

        CustomerServiceInfoVo customerServiceInfoVo = customerServiceInfoDao.findByMerchantStoreId(customerServiceInfoDto);
        if (StringUtils.isEmpty(customerServiceInfoVo)) {
            customerServiceInfoVo = new CustomerServiceInfoVo();
        }

        customerServiceInfoVo.setMemberId(memberFromReq.getId());

        return ServerResponse.createBySuccess(customerServiceInfoVo);
    }
}
